//
//  BelowHomeTableCell.m
//  GoldOperationClient
//
//  Created by yaxue wang on 2016/11/23.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "BelowHomeTableCell.h"
#import "HomeModel.h"
@implementation BelowHomeTableCell


- (void)initView{
    [super initView];
    self.backgroundColor =[UIColor whiteColor];


    UIImage *replyImage=[UIImage imageNamed:@"Ico_home_reply"];
    self.replyView=[[UIView alloc]initWithFrame:CGRectMake(WindowWidth-replyImage.size.width-45, 0, replyImage.size.width+35+10, 35)];
    [self addSubview:self.replyView];
   
    self.replyImg=[[UIImageView alloc]initWithFrame:CGRectMake(0, (35-replyImage.size.height)/2, replyImage.size.width, replyImage.size.height)];
    self.replyImg.userInteractionEnabled=YES;
    [self.replyView addSubview:self.replyImg];
   
    self.replyLab = [[UILabel alloc]initWithFrame:CGRectMake(replyImage.size.width+5, 0, 35, 35)];
    self.replyLab.userInteractionEnabled=YES;
    [self.replyView addSubview:self.replyLab];
   
    self.replyLab.textColor =MainColor;
    self.replyLab.font =F(12);
    [self.replyView bk_whenTapped:^{
        if (self.btnBlock) {
            self.btnBlock(self,HomeCellType_Relpay,nil);
        }
    }];

    UIImage *progressImage=[UIImage imageNamed:@"Ico_home_jiedan"];
    self.progressView=[[UIView alloc]initWithFrame:CGRectMake(WindowWidth-replyImage.size.width-45-progressImage.size.width-55, 0, progressImage.size.width+35+10, 35)];

    [self addSubview:self.progressView];
   

    self.progressImg=[[UIImageView alloc]initWithFrame:CGRectMake(0, (35-progressImage.size.width)/2, progressImage.size.width, progressImage.size.height)];
    [self.progressView addSubview:self.progressImg];
    self.progressImg.image=progressImage;
    self.progressImg.userInteractionEnabled=YES;
    
    self.progressLab =[[UILabel alloc]initWithFrame:CGRectMake(progressImage.size.width+5, 0, 35, 35)];
    self.progressLab.userInteractionEnabled=YES;
    [self.progressView addSubview:self.progressLab];
 
    self.progressLab.font =F(12);
    self.progressLab.textColor =MainColor;
    [self.progressView bk_whenTapped:^{
        if (self.btnBlock) {
            self.btnBlock(self,HomeCellType_Progress,nil);
        }
    }];
    
    UIImage *addImage=[UIImage imageNamed:@"Ico_home_add"];
    self.addView=[[UIView alloc]initWithFrame:CGRectMake(WindowWidth-replyImage.size.width-45-progressImage.size.width-55-addImage.size.width-70, 0, addImage.size.width+70, 35)];
    [self addSubview:self.addView];
    
    self.addImg=[[UIImageView alloc]initWithFrame:CGRectMake(0, (35-addImage.size.height)/2, addImage.size.width, addImage.size.height)];
    _addImg.image=addImage;
    self.addImg.userInteractionEnabled=YES;
    [self.addView addSubview:self.addImg];
    
    self.addLab = [[UILabel alloc]initWithFrame:CGRectMake(replyImage.size.width+5, 0, 70, 35)];
    self.addLab.userInteractionEnabled=YES;
    [self.addView addSubview:self.addLab];
    self.addLab.textColor =MainColor;
    self.addLab.font =F(12);
    self.addLab.text=@"补充设备";
    [self.addView bk_whenTapped:^{
        if (self.btnBlock) {
            self.btnBlock(self,HomeCellType_Add,nil);
        }
    }];
    

    self.pollingStateLab=[[UILabel alloc]init];
    [self addSubview:self.pollingStateLab];
    self.pollingStateLab.frame =CGRectMake(WindowWidth-65-15, (35-22)/2, 65, 22);
    self.pollingStateLab.textColor =MainColor;//C(@"1aa3aa");
    self.pollingStateLab.layer.masksToBounds=YES;
    self.pollingStateLab.layer.cornerRadius=4;
    self.pollingStateLab.layer.borderColor=MainColor.CGColor;//C(@"1aa3aa").CGColor;
    self.pollingStateLab.layer.borderWidth=1;
    self.pollingStateLab.font=F(12);
    self.pollingStateLab.textAlignment=NSTextAlignmentCenter;
    self.pollingStateLab.userInteractionEnabled=YES;
    [self.pollingStateLab bk_whenTapped:^{
        if (self.btnBlock) {
            self.btnBlock(self,HomeCellType_Progress,nil);
        }
    }];
    
    self.line =[[UILabel alloc]initWithFrame:CGRectMake(10, 0, WindowWidth-20, 0.5)];
    [self addSubview:self.line];
    self.line.backgroundColor =LineColor;
 
}

- (void)setModel:(id)model{
  
    HomeModel *order = model;

    self.replyLab.text=@"回复";
    self.replyLab.textColor =MainColor;
    self.replyImg.image=[UIImage imageNamed:@"Ico_home_reply"];

    if (order.H_state ==nil||[order.H_state isEqualToString:@""])
    {
        
    }else
    {
        NSInteger num=[order.H_state integerValue];
        //H_order_type 1 为报修单 2为巡检单
        if ([order.H_order_type isEqualToString:@"1"]) {
         
            self.replyView.hidden=NO;
            self.addView.hidden=NO;
            self.progressView.hidden=NO;
            self.pollingStateLab.hidden=YES;
            
            if(num ==1){
                //待接单
                //显示接单请求
                self.progressLab.text=@"接单";
                self.progressImg.image=[UIImage imageNamed:@"Ico_home_jiedan"];
            }else if (num==2)
            {  //待处理
                //显示开始处理按钮
                self.progressLab.text=@"处理";
                self.progressImg.image=[UIImage imageNamed:@"Ico_home_start"];
            }else if (num==4||num==5)
            {   //处理中
                //显示标记完成按钮
                //待挂起
                //一样---> 显示标记完成按钮
                self.progressLab.text=@"完成";
                self.progressImg.image=[UIImage imageNamed:@"Ico_home_sucess"];
            }else if (num==6)
            {
                //已挂起
                //显示恢复按钮
                self.progressLab.text=@"恢复";
                self.progressImg.image=[UIImage imageNamed:@"Ico_home_huifu"];
            }
            if (num==1) {
                self.replyView.hidden=YES;
                UIImage *addImage=[UIImage imageNamed:@"Ico_home_add"];
                UIImage *progressImage=[UIImage imageNamed:@"Ico_home_jiedan"];
                self.addView.frame=CGRectMake(WindowWidth-progressImage.size.width-55-addImage.size.width-70, 0, addImage.size.width+70, 35);
                self.progressView.frame=CGRectMake(WindowWidth-progressImage.size.width-45, 0, progressImage.size.width+35+10, 35);
                
            }else
            {
                UIImage *addImage=[UIImage imageNamed:@"Ico_home_add"];
                UIImage *replyImage=[UIImage imageNamed:@"Ico_home_reply"];
                UIImage *progressImage=[UIImage imageNamed:@"Ico_home_jiedan"];
                self.replyView.hidden=NO;
                self.addView.frame=CGRectMake(WindowWidth-replyImage.size.width-45-progressImage.size.width-55-addImage.size.width-70, 0, addImage.size.width+70, 35);
                self.progressView.frame=CGRectMake(WindowWidth-replyImage.size.width-45-progressImage.size.width-55, 0, progressImage.size.width+35+10, 35);
                self.replyView.frame=CGRectMake(WindowWidth-replyImage.size.width-45, 0, replyImage.size.width+35+10, 35);
                
            }

            if ((order.H_machine_name ==nil||[order.H_machine_name isEqualToString:@""])&&(order.H_machine_type_name ==nil||[order.H_machine_type_name isEqualToString:@""])) {
                
                self.addView.hidden=NO;
                
            }else if ((order.H_machine_name ==nil||[order.H_machine_name isEqualToString:@""])||(order.H_machine_type_name ==nil||[order.H_machine_type_name isEqualToString:@""])) {
                self.addView.hidden=NO;
                
                
                
            }else
            {
                self.addView.hidden=YES;
                
            }
            [self bk_whenTapped:^{
                if (self.btnBlock) {
                    self.btnBlock(self,HomeCellType_Detail,nil);
                }
            }];
            
        }else
        {
            //巡检单
            self.replyView.hidden=YES;
            self.addView.hidden=YES;
            self.progressView.hidden=YES;
            self.pollingStateLab.hidden=NO;
//
            if(num ==1){
                //待接单
                //显示接单请求
                self.pollingStateLab.text=@"接单";
               
            }else if (num==2)
            {  //待处理
                //显示开始处理按钮
                self.pollingStateLab.text=@"开始巡检";
            }else
            {
                self.pollingStateLab.hidden=YES;

            }
//            [self bk_whenTapped:^{
//                if (self.btnBlock) {
//                    self.btnBlock(self,HomeCellType_DetailPolling,nil);
//                }
//            }];
            
        }
        

    }
//    
    





}
@end


